<template>
  <div class="container" >
    <el-form :inline="true" :model="ruleForm" ref="ruleForm" :rules="rules"  class="demo-form-inline">
      <el-form-item label="病人类型" prop="type">
        <el-select v-model="ruleForm.type" placeholder="请选择" style="width: 100px" @change="submitForm">
          <el-option label="住院病人" value="0"></el-option>
          <el-option label="门诊病人" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="唯一标识" prop="no">
        <el-input v-model="ruleForm.no" placeholder="病案号/患者唯一标识/住院号/门诊号" @keyup.native.13="submitForm" ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">查询</el-button>
        <el-button type="" @click="resetForm">重置</el-button>
        <el-button type="" @click="close">关闭</el-button>
      </el-form-item>
    </el-form>
    <el-row >
      <el-col :span="24">
        <el-table
          :data="tableData"
          stripe
          @current-change="radioChange"
          style="width: 100%">
          <el-table-column
            type="index"
            width="50">
          </el-table-column>
          <el-table-column label="选择" width="50">
            <template slot-scope="scope">
              <el-button size="mini" type="success" icon="el-icon-check" circle @change="radioChange(scope.row)" title="选择该数据"></el-button>
            </template>
          </el-table-column>
          <el-table-column
            sortable
            prop="patient_no"
            label="病案号"
            width="180">
          </el-table-column>
          <el-table-column
            sortable
            prop="patient_name"
            label="姓名"
            width="120">
          </el-table-column>
          <el-table-column
            prop="bed_no"
            sortable
            label="床位号">
          </el-table-column>
          <el-table-column
            prop="out_dept"
            sortable
            label="就诊科室">
          </el-table-column>
          <el-table-column
            prop="in_dept"
            sortable
            label="住院科室">
          </el-table-column>
          <el-table-column
            prop="inpatient_no"
            sortable
            label="住院号">
          </el-table-column>
          <el-table-column
            prop="outpatient_no"
            sortable
            label="门诊号">
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>

<script>
/* eslint-disable*/
export default {
  name: 'patientWsChoice',
  data() {
    return {
      ruleForm: {
        no: '',
        type: '',
      },
      rules: {
        no: [
          { required: true, message: '请输入', trigger: 'blur' },
        ],
        type: [
          { required: true, message: '请选择病人类型', trigger: 'change' }
        ]
      },
      tableData: []
    }
  },
  methods: {
    //提交表单
    submitForm() {
      let valid = this.$refs.ruleForm.validate((valid) => {
        if (!valid) {
          return false
        }
        this.query()
      })
    },

    //提交表单
    query() {
      this.ruleForm.no = this.strings.trimrl(this.ruleForm.no)
      this.utilVue.loadShow(true)
      this.tableData = []
      this.$ajax.get(`/his/getHisPatient?no=${this.ruleForm.no}&type=${this.ruleForm.type}`).then((response) => {
        console.log('response', response)
        if(response.code == 0) {
          this.tableData = response.data
        }
        this.utilVue.loadHide()
      })
    },

    //重置
    resetForm() {
      this.$refs.ruleForm.resetFields()
      this.tableData = []
    },

    //关闭
    close() {
      this.$emit('close')
    },
    //选择
    radioChange(row) {
      console.log('row',row)
      this.$emit('select-change',row)
      this.close()
    }
  }
}
</script>

<style lang="scss" scoped>
  .container {
    height: 100%;
    background-color: #fff;
  }
</style>
